﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LeHouse.Server.Dto;
namespace LeHouse.Server.Dal
{
    /// <summary>
    /// 户内部分DAL的操作
    /// </summary>
    public class Collateral_IndoorDAL : GenericBaseDAL<Collateral_Indoor>
    {
        /// <summary>
        /// 根据报告号去查询户内是否有该条记录
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public int count(string P_ReportNumber)
        {
            int C_projectcount;
            string sql = @"select count(I_storey) from Collateral_Indoor  where P_ReportNumber=@P_ReportNumber ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = P_ReportNumber;
                    cmd.Parameters.Add(p);
                    C_projectcount = Convert.ToInt32(cmd.ExecuteScalar());
                }
                return C_projectcount;
            }
        }

        /// <summary>
        /// 根据报告号去查询户内的信息
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public Collateral_Indoor Facilitybyid(string P_ReportNumber)
        {
            Collateral_Indoor munity = new Collateral_Indoor();
            string sql = @"select * from Collateral_Indoor  where P_ReportNumber=@P_ReportNumber ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = P_ReportNumber;
                    cmd.Parameters.Add(p);
                    var reader = cmd.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            munity.T_ReportNumber = reader["P_ReportNumber"].ToString();
                            munity.T_purposeID = Convert.ToInt32(reader["I_purposeID"]);
                            munity.T_Floor = reader["I_floor"].ToString();
                            munity.T_Storey = Convert.ToInt32(reader["I_storey"]);
                            munity.T_OrientationID = Convert.ToInt32(reader["I_orientationID"]);
                            munity.T_ResidenceID = Convert.ToInt32(reader["I_residenceID"]);
                            munity.T_SeveralBedroom = reader["I_severalBedroom"].ToString();
                            munity.T_Severaldrawing = reader["I_severaldrawing"].ToString();
                            munity.T_Severalbathroom = reader["I_severalbathroom"].ToString();
                            munity.T_SeveralKITCHEN = reader["I_severalKITCHEN"].ToString();
                            munity.T_DrawingID = Convert.ToInt32(reader["I_drawingID"]);
                            munity.T_Roomdescribe = reader["I_roomdescribe"].ToString();
                            munity.T_HabitableID = Convert.ToInt32(reader["I_habitableID"]);
                            munity.T_Habitable = reader["I_habitable"].ToString();
                            munity.T_ToiletID = Convert.ToInt32(reader["I_toiletID"]);
                            munity.T_Toilet = reader["I_toilet"].ToString();
                            munity.T_KitchenID = Convert.ToInt32(reader["I_kitchenID"]);
                            munity.T_Kitchen = reader["I_kitchen"].ToString();
                            munity.T_Explain = reader["I_explain"].ToString();
                          //  munity.T_State = Convert.ToInt32(reader["I_state"]);
                         //   munity = Convert.ToInt32(reader["I_Buildingafew"]);
                                                                                  
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
                return munity;
            }
        }
    }
}
